#include "includes.h"

char *
strcpy( 
    char *strDestination, 
    const char *strSource )
{
    char *Dest = strDestination;
    
    do {
        *strDestination++ = *strSource;
    } while(*strSource++);

return Dest;
}


int 
strcmp( 
    const char *string1, 
    const char *string2 )
{
    int cmp=0;
    
    while(!cmp && *string1 && *string2) {
        cmp = *string1++ - *string2++;
    }

return cmp;
}    

unsigned int
strlen( 
    const char *string )
{
    unsigned int len=0;
    
    while(*string++) {
        len++;
    }
return len;
}

char *
strchr( 
    const char *string, 
    int c )

{
    
    do{
        if (c == *string)
            return (char*)string;         
    
    } while(*string++ );
    
    
return NULL;
}




/*
    Converts a hex string to a ULONG
    
    if string typed is: 12345678
    
    In memory == Mem Address :  01234567 
                 String chars:  12345678
    
                
    Hence first char will be shifted to the MSB
    Str is the string
    Val pointer to the storage location.                
                
*/
int
strtohex(
    char *Str,
    unsigned int *Val
    )
{
    int Len;
    unsigned int Value = 0;
    int Shift = 0;
    int RetVal=FALSE;
    

    Len = strlen(Str);
    Shift = (Len-1) * 4;
    
    while (Len--) {
    
        RetVal = TRUE;
        
        //
        // nibble at a time
        //
        if (*Str <= '9' && *Str >= '0') {
            Value |= ((*Str - '0') << Shift);
        } else if (*Str <= 'f' && *Str >= 'a') {
            Value |= ((*Str - 'a' + 10) << Shift);
        } else if(*Str <= 'F' && *Str >= 'A') {
            Value |= ((*Str - 'A' + 10) << Shift);            
        } else if ((*Str == ' ') || (*Str == '\0')) {
            break;
        
        } else {
            Value = 0;
            
            RetVal=FALSE;
            
            break;
        }
        Shift -= 4;
        Str++;
    }
    
    *Val = Value;
    
return RetVal;    
}


void *
memset(
    void *ptr,
    int c,
    unsigned int size)
{

    while (size--) {
        ((char*)ptr)[size] = c;
    }
    
    return ptr;
}



void *
memcpy( 
    void *dest, 
    const void *src, 
    unsigned int count )
{
    while (count--) {
        ((char*)dest)[count] = ((char*)src)[count];
    }

return dest;
}    


int 
memcmp( 
    const char * buf1, 
    const char * buf2, 
    unsigned int count )
{

    int cmpval=0;
    
    while (!cmpval && count--) {
        cmpval = *buf1++ - *buf2++;
    }

    return cmpval;
}    

